/** @file read.S
 *
 * @brief read sycall wrapper
 *
 * @author 	
 * 
 */

#include <asm.h>
#include <bits/swi.h>
#include <bits/errno.h>

	.file "read.S"

FUNC(read)
	@ Add code here.  Put your names at the top.

read:
	@ Store the lr to safely go back to the user program
	SWI	READ_SWI
	CMP	r0,#0
	BGE	out

	@ Negative return value
	LDR	r5, =errno
	RSB	r0, r0, #0	@ Negate the return value
	STR	r0, [r5]	@ Store it in errno
	MOV	r0, #-1		@ return -1

out:
   	@ Restore lr and go back to the user program
 	MOV	pc, lr	

